package com.example.bai6;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Locale;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class MyAdapter extends ArrayAdapter<Student>{

	Activity context;
	int resourceid;
	ArrayList<Student> arr;
	public MyAdapter(Context context, int resource, ArrayList<Student> objects) {
		super(context, resource,objects);
		// TODO Auto-generated constructor stub
		this.context=(Activity) context;
		this.resourceid=resource;
		this.arr=objects;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if(convertView==null)
		{
			convertView=context.getLayoutInflater().inflate(resourceid, null);
		}
		TextView txtMaVaTen= (TextView) convertView.findViewById(R.id.txtMaVaTen);
		TextView txtThongTinKhac= (TextView) convertView.findViewById(R.id.txtThongTinKhac);
		
		Student s=arr.get(position);
		txtMaVaTen.setText(s.getId()+" - "+s.getName());
		
		SimpleDateFormat df= new SimpleDateFormat("dd/mm/yyyy",Locale.getDefault());
		txtThongTinKhac.setText((s.isGender()?"Nữ-":"Nam-")+df.format(s.getBirthday())+s.getPlaceOfBirth());
		
		return convertView;
	}

}
